<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宏命令 命令模式和组合模式 es5</title>
</head>

<body>
    <script>
        var com1 = {
            execute:function(){
                console.log("打开电视");
            }
        }
        var com2 = {
            execute:function(){
                console.log("拿起饮料");
            }
        }
        var com3 = {
            execute:function(){
                console.log("开着空调");
            }
        }
        // 宏命令对象
        var command = function(){
            return{
                commandList:[],
                add:function(command){
                    this.commandList.push(command)
                },
                execute:function(){
                    for(let command of this.commandList){
                        // console.log(command );
                        command.execute()
                    }
                }
            }
        }
        var c = command()
        c.add(com1)
        c.add(com2)
        c.add(com3)
        c.execute()
    </script>
</body>

</html>